function SWEP:GetViewModelPosition (pos, ang)
	tgm.VMmul = math.Clamp (tgm.VMmul + tgm.VMmuldir * FrameTime() * tgm.VMspeed, 0, 1)
	
	local mul = tgm.VMmul
	
	self.BobScale = 1 - (mul * 0.8)
	self.SwayScale = 1 - (mul * 0.8)
	if mul == 0 then return pos, ang end

	local PosMod = tgm.VMPos
	local AngMod = tgm.VMAng + tgm.VMAngAdd
	
	if AngMod then
		ang = ang * 1
		ang:RotateAroundAxis (ang:Right(), 		AngMod.x * mul)
		ang:RotateAroundAxis (ang:Up(), 		AngMod.y * mul)
		ang:RotateAroundAxis (ang:Forward(), 	AngMod.z * mul)
	end

	local Right 	= ang:Right()
	local Up 		= ang:Up()
	local Forward 	= ang:Forward()

	pos = pos + PosMod.x * Right * mul
	pos = pos + PosMod.y * Forward * mul
	pos = pos + PosMod.z * Up * mul
	
	return pos, ang
end

SWEP.StandardViewModelDrawn = SWEP.ViewModelDrawn

function SWEP:ViewModelDrawn ()
	if tgm.VMmul > 0 or tgm.CVAR_AlwaysRender:GetBool() then
		self:TGMDoAlwaysThink()
		self:TGMViewModelDrawn()
	else
		self:TGMDoAlwaysThink()
		self:StandardViewModelDrawn()
	end
end

local scrSize = tgm.ScreenSize

local matScreen 	= Material ("models/weapons/v_toolgun/screen")
local RTTexture 	= GetRenderTarget ("GModToolgunScreen", scrSize, scrSize)

function SWEP:TGMViewModelDrawn ()
 	local mode 	= gmod_toolmode:GetString()
 	local NewRT = RTTexture
	
 	matScreen:SetMaterialTexture ("$basetexture", NewRT)
 	 
 	local OldRT = render.GetRenderTarget()

 	render.SetRenderTarget (NewRT)
 	render.SetViewPort (0, 0, scrSize, scrSize)
 	cam.Start2D()
	
	--black background
 	surface.SetDrawColor (0, 0, 0, 255)
 	surface.DrawRect (0, 0, scrSize, scrSize)
	
	--let the GAMES begin
	if tgm.CurrentGame then
		if tgm.VMmuldir >= 1 then
			if tgm.CurrentGame.Paused then
				print ("unpause . . .")
				tgm.CurrentGame:Unpause()
				tgm.CurrentGame.Paused = false
			end
			tgm.CurrentGame:Think()
		else
			if not tgm.CurrentGame.Paused then
				print ("pause . . .")
				tgm.CurrentGame:Pause()
				tgm.CurrentGame.Paused = true
			end
		end
		tgm.CurrentGame:Render()
		tgm:DrawMouse()
	else
		--load in all the game files
		tgm:LoadGames()
		--load the selection game
		tgm:ChangeGame ("game_select")
	end
   
 	cam.End2D()
 	render.SetRenderTarget (OldRT)
end

function SWEP:TGMDoAlwaysThink()
	if tgm.CurrentGame then
		tgm.CurrentGame:AlwaysThink()
	end
end

SWEP.StandardHolster = SWEP.Holster

function SWEP:Holster ()
	self:StandardHolster()
	
	print ("holstering")
	
	if tgm.CurrentGame then
		print ("attempting pause . . .")
		if not tgm.CurrentGame.Paused then
			tgm.CurrentGame:Pause()
			tgm.CurrentGame.Paused = true
		end
	end
end

SWEP.StandardDeploy = SWEP.Deploy

function SWEP:Deploy ()
	return self:StandardDeploy()
end
